<template>
	<div class="all allcontainer" v-loading="loading">
		<div class="h2">{{myInfo.ScoreName}}申请记录</div>
		<div class="bg-white">
		<div id="components-form-demo-advanced-search">
			<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="标题">
							<a-input class="field-right" placeholder="请输入标题搜索" v-decorator="[`key`]" />
						</a-form-item>
					</a-col>
					<a-col :span="16">
						<a-button type="primary" html-type="submit">搜索</a-button>
						<a-button @click="handleReset">重置</a-button>
						<a-button type="primary" @click="addList()">新增</a-button>
						<span class="more-search" @click="isMore=!isMore">高级筛选　<i>{{isMore?'⤧':'⤩'}}</i></span>
					</a-col>
					<div style="margin-top: 70px;" v-show="isMore">
						<a-col :span="8">
							<a-form-item label="状态">
								<a-select :allowClear="true" v-decorator="['state']" placeholder="全部" optionFilterProp="children" showSearch>
									<a-select-option v-for="(item, index) in TypeList" :key="index" :value="item.Key">{{ item.Value }}</a-select-option>
								</a-select>
							</a-form-item>
						</a-col>
					</div>
				</a-row>
			</a-form>
		</div>
		<div class="table">
			<el-table stripe ref="singleTable" :data="data" highlight-current-row style="width: 100%">
				<el-table-column prop="Title" label="标题" min-width="100" fixed="left"></el-table-column>
				<!-- <el-table-column prop="AddUserNo" label="学号" min-width="100" ></el-table-column> -->
				<el-table-column prop="ApplyItemNodeName" label="申请项" min-width="120" align="center"></el-table-column>
				<el-table-column prop="IsManager" label="状态" min-width="100">
					<template slot-scope="scope">
						<!-- {{ scope.row.IsManager==true?'管理员':'成员' }} -->
						<a-tag color="green" v-if="scope.row.State==3"> {{scope.row.StateName}} </a-tag>
						<a-tag color="pink" v-else> {{scope.row.StateName}} </a-tag>
					</template>
				</el-table-column> 
				<el-table-column pr0.o3p="AddTime" label="时间" min-width="100" align="center">
					<template slot-scope="scope">
						{{ scope.row.AddTime }}
						</template>
				</el-table-column>
				<el-table-column prop="IsEnable" label="操作" width="220" fixed="right">
					<template slot-scope="scope">
						<div class="user-btn user-btn-auto">
							<span class="detail" v-if="!scope.row.IsManager" @click="look(scope.row)">查看</span>
							<span class="modify" v-if="scope.row.State==1" @click="update(scope.row)">修改</span>
							<span class="examine"v-if="scope.row.State == 1" @click="sumbitapply(scope.row,'manage')">提交审批</span>
							<span class="delete" v-if="!scope.row.IsManager&&scope.row.State==1" @click="deletemember(scope.row)">删除</span>
						</div>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage"
			 :page-sizes="pagination.pageSizeOptions" :page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper"
			 :total="pagination.total"></el-pagination>
		</div>
		</div>
		<add :time="time" :type="loadingtype" v-if="addIf" @closeFun="closeFun"></add> 
		<update :text="updatetext"  v-if="updateIf" :time="time" @closeFun="closeFun"></update>
		<detail :text="detailtext"  v-if="detailIf"  :time="time" @closeFun="closeFun"></detail>
	</div>
</template>

<script>
	import Func from '@/utils/func';
	import Cache from '@/utils/cache'
	import {
		UserApplyItemPageList,
		DoDeleteUserApplyItem,
		DoSubmitUserApplyItem,
		GetUserApplyItemStateList
	} from '@/api/follow';
	import add from './addCredit'
	import update from './UpdateCredit.vue'
	import detail from './UserCreditApplyDetail.vue'
	const data = [];
	export default {
		components: {
			add,
			update,
			detail
		},
		data() {
			return {
				data,
				isMore:false,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				loadingtype:0,
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				addIf: false,
				text: {},
				detailtext:{},
				codeID:'',
				visible: false,
				confirmLoading: false,
				itemId: '',
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				pages: {
					pageIndex: 1,
					pageSize: 20
				},
				TypeList:[],
				tableHeight: parseFloat(window.innerHeight - 160),
				TypeIDList: [],
				DepartCodeList: [],
				ProjectIDList: [],
				ishaveid: true,
				selectList: {},
				showModal: false,
				UserInfo: Cache.get('myInfo'),
				myInfo: Cache.get('myInfo'),
				ChairmanNo: this.$route.query.ChairmanNo,
				linktype: 1,
				ID: this.$route.query.ID,
				visible: false,
				deletelist: {},
				time:'',
				codeIf:false,
				detailIf:false,
				updateIf:false,
				updatetext:{}
			};
		},
		computed: {},
		created() {
			this.getList();
			this.getOtherList()
		},
		mounted() {},
		methods: {
			sumbitapply(text) {
				let that = this
				this.$confirm({
					title: '提示',
					content: `您确定提交审批吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {}
						data.id = text.ID
						let res = await DoSubmitUserApplyItem(data);
						if (res.data.code == 0) {
							that.$message.success(res.data.msg)
							that.getList()
						} else {
							that.$message.error(res.data.msg)
						}
					}
				})
			},
			handleCancel(e) {
				this.visible = false
				this.getList()
			},
			deletemember(text) {
				// this.visible = true
				// this.deletelist = text
				let that=this
				this.$confirm({
					title: '提示',
					content: `您确定删除此条记录吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {}
						data.id = text.ID
						let res = await DoDeleteUserApplyItem(data);
						if(res.data.code==0){
							that.getList()
							that.$message.success(res.data.msg)
						}else{
							
							that.$message.error(res.data.msg)
						}
					}
				})
			},
			update(text) {
				this.updatetext = text
				this.time=new Date()
				this.updateIf = true
			},
			look(text) {
				this.detailtext = text
				this.time=new Date()
				this.detailIf = true
			},
			handleChange(val) {
				this.currentRow = val;
				if (val.ID) {
					this.ishaveid = false
					this.selectList = val
				} else {
					this.ishaveid = true
				}
			},
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					this.values = values;
					this.getList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.getList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				let res = await UserApplyItemPageList(data);
				this.loading = false;
				this.data = res.data.data;
				const pagination = { ...this.pagination
				};
				pagination.total = res.data.pageInfo.TotalItemCount;
				this.pagination = pagination;
			},
			async getOtherList() {
				let res = await GetUserApplyItemStateList()
				this.TypeList = res.data.data
			},
			addList() {
				this.loadingtype=1
				this.time=new Date()
				this.addIf = !this.addIf;
			},
			modifyList(text) {
				text = Object.assign(text, {
					time: new Date()
				});
				this.addIf = !this.addIf;
				this.text = text;
			},
			closeFun(index) {
				this.showModal = false
				this.addIf=false
				this.detailIf=false
				this.updateIf=false
				this.getList()
			},
		}
	};
</script>

